const util = require('../util');

class PackageTemplate {
  constructor(config) {
    this.config = config;
  }

  generateEnv() {
    var text = `
      {
        "apps": [
          {
            "name": "${this.config.dbName}_test",
            "script": "server.js",
            "watch": false,
            "cwd": ".",
            "instances": "max",
            "exec_mode": "cluster",
            "log_file": "log/access.log",
            "error_file": "log/error.log",
            "out_file": "log/out.log",
            "env_test": {
              "NODE_ENV": "test",
              "API_PORT": "5000",
              "JWT_KEY": "7mXBS29DDpMwU6Y7xE3TfDczOHmmsdMl",
              "WS": "ws://111.198.33.47:6006",
              "RPC": "http://111.198.33.47:5005",
              "IPFS": "http://127.0.0.1:5001/api/v0",
              "DB_HOST": "${this.config.host}",
              "DB_NAME": "${this.config.dbName}",
              "DB_USER": "${this.config.user}",
              "DB_PASSWORD": "${this.config.pwd}",
              "DB_PORT": "${this.config.port}"
            }
          },
          {
            "name": "${this.config.dbName}_timer_test",
            "script": "chainsql_timer/timerService.js",
            "watch": false,
            "cwd": ".",
            "log_file": "log/access_timer.log",
            "error_file": "log/error_timer.log",
            "out_file": "log/out_timer.log",
            "env_test": {
              "NODE_ENV": "test",
              "API_PORT": "5000",
              "JWT_KEY": "7mXBS29DDpMwU6Y7xE3TfDczOHmmsdMl",
              "WS": "ws://111.198.33.47:6006",
              "RPC": "http://111.198.33.47:5005",
              "IPFS": "http://127.0.0.1:5001/api/v0",
              "DB_HOST": "${this.config.host}",
              "DB_NAME": "${this.config.dbName}",
              "DB_USER": "${this.config.user}",
              "DB_PASSWORD": "${this.config.pwd}",
              "DB_PORT": "${this.config.port}"
            }
          }
        ]
      }
    
      `;
    return text;
  }

  generateGitignore() {
    var text = `node_modules\npackage-lock.json\nlog`;
    return text;
  }
  generatePrettierrc() {
    var text = `module.exports = {
      printWidth: 80, //一行的字符数，如果超过会进行换行，默认为80
      tabWidth: 2, //一个tab代表几个空格数，默认为80
      useTabs: false, //是否使用tab进行缩进，默认为false，表示用空格进行缩减
      singleQuote: true, //字符串是否使用单引号，默认为false，使用双引号
      semi: true, //行位是否使用分号，默认为true
      trailingComma: 'none', //是否使用尾逗号，有三个可选值"<none|es5|all>"
      bracketSpacing: true //对象大括号直接是否有空格，默认为true，效果：{ foo: bar }
    };`;
    return text;
  }
}

exports = module.exports = PackageTemplate;
